package com.ruoyi.project.beautyflower.userProtocol.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.beautyflower.userProtocol.domain.UserProtocol;
import com.ruoyi.project.beautyflower.userProtocol.service.IUserProtocolService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 用户协议 信息操作处理
 * 
 * @author lxs
 * @date 2018-10-11
 */
@Controller
@RequestMapping("/beautyflower/userProtocol")
public class UserProtocolController extends BaseController
{
    private String prefix = "beautyflower/userProtocol";
	
	@Autowired
	private IUserProtocolService userProtocolService;
	
	@RequiresPermissions("beautyflower:userProtocol:view")
	@GetMapping()
	public String userProtocol()
	{
	    return prefix + "/userProtocol";
	}
	
	/**
	 * 查询用户协议列表
	 */
	@RequiresPermissions("beautyflower:userProtocol:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(UserProtocol userProtocol)
	{
		startPage();
        List<UserProtocol> list = userProtocolService.selectUserProtocolList(userProtocol);
		return getDataTable(list);
	}
	
	/**
	 * 新增用户协议
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存用户协议
	 */
	@RequiresPermissions("beautyflower:userProtocol:add")
	@Log(title = "用户协议", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(UserProtocol userProtocol)
	{		
		return toAjax(userProtocolService.insertUserProtocol(userProtocol));
	}

	/**
	 * 修改用户协议
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		UserProtocol userProtocol = userProtocolService.selectUserProtocolById(id);
		mmap.put("userProtocol", userProtocol);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存用户协议
	 */
	@RequiresPermissions("beautyflower:userProtocol:edit")
	@Log(title = "用户协议", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(UserProtocol userProtocol)
	{		
		return toAjax(userProtocolService.updateUserProtocol(userProtocol));
	}
	
	/**
	 * 删除用户协议
	 */
	@RequiresPermissions("beautyflower:userProtocol:remove")
	@Log(title = "用户协议", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(userProtocolService.deleteUserProtocolByIds(ids));
	}
	
}
